home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html.parser;
-
- import java.io.IOException;
- import java.io.Reader;
- import javax.swing.text.ChangedCharSetException;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.html.HTML;
- import javax.swing.text.html.HTMLEditorKit;
- import javax.swing.text.html.HTML.Attribute;
-
- public class DocumentParser extends Parser {
- private int inbody;
- private int intitle;
- private int inhead;
- private int instyle;
- private boolean seentitle;
- private HTMLEditorKit.ParserCallback callback = null;
- private boolean ignoreCharSet = false;
- private static final boolean debugFlag = false;
- private static HTML.UnknownTag EndOfLineTag = new HTML.UnknownTag("__EndOfLineTag__");
-
- public DocumentParser(DTD var1) {
- super(var1);
- }
-
- private void debug(String var1) {
- System.out.println(var1);
- }
-
- protected void handleComment(char[] var1) {
- this.callback.handleComment(var1, ((Parser)this).getCurrentPos());
- }
-
- protected void handleEmptyTag(TagElement var1) throws ChangedCharSetException {
- Element var2 = var1.getElement();
- if (var2 == super.dtd.meta && !this.ignoreCharSet) {
- SimpleAttributeSet var3 = ((Parser)this).getAttributes();
- if (var3 != null) {
- String var4 = (String)var3.getAttribute(Attribute.CONTENT);
- if (var4 != null) {
- if ("content-type".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
- throw new ChangedCharSetException(var4, false);
- }
-
- if ("charset".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
- throw new ChangedCharSetException(var4, true);
- }
- }
- }
- }
-
- if (this.inbody != 0 || var2 == super.dtd.meta || var2 == super.dtd.base || var2 == super.dtd.isindex || var2 == super.dtd.style || var2 == super.dtd.link) {
- if (var1.fictional()) {
- this.callback.handleSimpleTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
- } else {
- this.callback.handleSimpleTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
- ((Parser)this).flushAttributes();
- }
- }
-
- }
-
- protected void handleEndTag(TagElement var1) {
- Element var2 = var1.getElement();
- if (var2 == super.dtd.body) {
- --this.inbody;
- } else if (var2 == super.dtd.title) {
- --this.intitle;
- this.seentitle = true;
- } else if (var2 == super.dtd.head) {
- --this.inhead;
- } else if (var2 == super.dtd.style) {
- --this.instyle;
- }
-
- this.callback.handleEndTag(var1.getHTMLTag(), ((Parser)this).getCurrentPos());
- }
-
- protected void handleError(int var1, String var2) {
- this.callback.handleError(var2, ((Parser)this).getCurrentPos());
- }
-
- protected void handleStartTag(TagElement var1) {
- Element var2 = var1.getElement();
- if (var2 == super.dtd.body) {
- ++this.inbody;
- } else if (var2 != super.dtd.html) {
- if (var2 == super.dtd.head) {
- ++this.inhead;
- } else if (var2 == super.dtd.title) {
- ++this.intitle;
- } else if (var2 == super.dtd.style) {
- ++this.instyle;
- }
- }
-
- if (var1.fictional()) {
- this.callback.handleStartTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
- } else {
- this.callback.handleStartTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
- ((Parser)this).flushAttributes();
- }
-
- }
-
- protected void handleText(char[] var1) {
- if (var1 != null && (this.inbody != 0 || this.instyle != 0 || this.intitle != 0 && !this.seentitle)) {
- this.callback.handleText(var1, ((Parser)this).getCurrentPos());
- }
-
- }
-
- public void parse(Reader var1, HTMLEditorKit.ParserCallback var2, boolean var3) throws IOException {
- this.ignoreCharSet = var3;
- this.callback = var2;
- ((Parser)this).parse(var1);
- SimpleAttributeSet var4 = new SimpleAttributeSet();
- var4.addAttribute("__EndOfLineString__", ((Parser)this).getEndOfLineString());
- var2.handleSimpleTag(EndOfLineTag, var4, ((Parser)this).getCurrentPos());
- }
- }
-